/*
 * @Author: gk 
 *  平台升级打包
 * @Date: 2018-03-15 14:44:57 
 * @Last Modified by: csy
 * @Last Modified time: 2019-05-27 17:03:18
 */
layui.config({
}).use(['element', 'zlConfig', 'zlContext', 'table', 'layer', 'form', 'zlSelectEx', 'zlPinYin', 'upload'], function (exports) {
	var $ = layui.$
		, zlContext = layui.zlContext
		, layer = layui.layer
		, table = layui.table
		, form = layui.form
		, zlPinYin = layui.zlPinYin
		, zlConfig = layui.zlConfig
		, statusName = zlConfig.global.result.statusName
		, msgName = zlConfig.global.result.msgName
		, dataName = zlConfig.global.result.dataName
		, OK = zlConfig.global.result.okState
		, fullheight = 'full-30'
		, customCurr = 1
		, loadingLayer
		, intervalId = undefined;

	var fromlayerIndex,
		treeLayerIndex,
		packProcessTimer,
		processLayerIndex,
		isloadsearch = false,
		isPrvFinish = true;

	//渲染版本更新信息列表
	var versionPackTb = table.render({
		elem: '#tbVersionPack'
		, sortload: true
		, height: fullheight
		, response: zlConfig.global.gridResponse
		, limit: 20
		, limits: [20, 50, 100, 200, 500, 1000]
		, page: true
		, updId: "FA7EBD527DCF4DE6978B38B6EC4203F0"
		, toolbar: "#toolbarVersionPack"
		, defaultToolbar: ['filter']
		, cols: [[ //表头
			{ type: 'numbers', fixed: 'left', title: '#' }
			, { type: 'checkbox', fixed: 'left' }
			, { field: 'VERP_SUOSXT', title: '所属系统', sort: true, sortload: false, width: 200 }
			, { field: 'VERP_BANB', title: '版本', sort: true, width: 200 }
			, { field: 'VERP_MIAOS', title: '版本描述', sort: true, width: 300 }
			, { field: 'VERP_GENGXSJ', title: '打包时间', sort: true, width: 150 }
			, { field: 'SYS_MODIFYTIME', title: '最后修改时间', sort: true, width: 150 }
			, { field: 'VERP_GENGXBLJ', title: '更新包路径' }
			, { fixed: 'right', width: 300, title: '操作', align: 'center', toolbar: '#barVersionPack' }
		]]
		, event:
		{
			onRowdbClick: function (field, row) {
				gridAction.viewRow(row);
			}
		}
	});

	var treeNodeTId = {};

	versionPackJson = {
		tableModel: [],
		lib: [],
		script: [],
		file: [],
		menu: [],
		VERP_CAOZXT: '',
		VERP_DATABASE: '',
		VERP_ZUIXBB: '',
		getTreeNodes: function (type) {
			return this[type];
		},
		setTreeNodes: function (type, nodes) {
			this[type] = nodes;
		},
		reset: function () {
			this.file = [];
			this.lib = [];
			this.script = [];
			this.file = [];
			this.menu = [];
			this.VERP_CAOZXT = '';
			this.VERP_DATABASE = '';
			this.VERP_ZUIXBB = '';
		}
	}
	var gridAction = {
		currentEditObj: undefined,
		gridEdit: function (catlog, row, type, readonly) {
			var readonly = readonly && readonly != 0 ? 'disabled' : '';
			var frm = [
				'<div class="site-block" lay-filter="divgridField"> <form id ="frmGridField" class="layui-form"  action="">'
				, '	<div class="layui-form-item layui-hide">'
				, '		<div class="layui-input-block">'
				, '			<input type="text" name="EDITTYPE" class="layui-input">'
				, '			<input type="text" name="RWID" class="layui-input">'
				, '			<input type="text" name="WJZY_LEIX" class="layui-input">'
				, '		</div>'
				, '	</div>'
				, '	<div class="layui-form-item">'
				, '		<label class="layui-form-label">所属系统:</label>'
				, '		<div class="layui-input-block">'
				, '			<select name="VERP_SUOSXT" lay-verify="required" class="select-ext" zlcomponent ' + readonly + ' lay-filter="VERP_SUOSXT"  settings="{titlefield: \'VALUE\', valuefield: \'VALUE\',dataurl:\'' + layui.cache['contentPath'] + '/manager/coredictionary/querydictionarybyid?RWID=1C630186B5FF40E2959E4B09CA2D0BFC\'}"></select>'
				, '		</div>'
				, '	</div>'
				, '	<div class="layui-form-item">'
				, '		<label class="layui-form-label">版本:</label>'
				, '		<div class="layui-input-block">'
				, '			<input type="text" name="VERP_BANB" lay-verify="required|verifyBackspace" ' + readonly + ' class="layui-input" maxlength="33">'
				, '		</div>'
				, '	</div>'
				, '	<div class="layui-form-item">'
				, '		<label class="layui-form-label">操作系统要求:</label>'
				, '		<div class="layui-input-block">'
				, '			<select name="VERP_CAOZXT" ' + readonly + ' >'
				, '				<option value="">所有</option>'
				, '				<option value="Windows">Windows</option>'
				, '				<option value="Linux">Linux</option>'
				, '			</select>'
				, '		</div>'
				, '	</div>'
				, '	<div class="layui-form-item">'
				, '		<label class="layui-form-label">数据库要求:</label>'
				, '		<div class="layui-input-block">'
				, '			<select name="VERP_DATABASE" ' + readonly + ' >'
				, '				<option value="">所有</option>'
				, '				<option value="oracle">oracle</option>'
				, '				<option value="mysql">mysql</option>'
				, '				<option value="sqlserver">sqlserver</option>'
				, '				<option value="dm">dm</option>'
				, '				<option value="jc">jc</option>'
				, '			</select>'
				, '		</div>'
				, '	</div>'
				, '	<div class="layui-form-item">'
				, '		<label class="layui-form-label">平台最小版本要求:</label>'
				, '		<div class="layui-input-block">'
				, '			<input maxlength="33" type="text" name="VERP_ZUIXBB" ' + readonly + ' class="layui-input">'
				, '		</div>'
				, '	</div>'
				, '	<div class="layui-form-item">'
				, '		<label class="layui-form-label">业务系统最小版本要求:</label>'
				, '		<div class="layui-input-block">'
				, '			<input maxlength="33" type="text" name="VERP_YWZUIXBB" ' + readonly + ' class="layui-input">'
				, '		</div>'
				, '	</div>'
				, '	<div class="layui-form-item">'
				, '		<label class="layui-form-label">版本描述:</label>'
				, '		<div class="layui-input-block">'
				, '			<textarea  name="VERP_MIAOS" maxlength="1333" lay-verify="required" ' + readonly + ' class="layui-textarea"></textarea>'
				, '		</div>'
				, '	</div>'
				, '	<div class="layui-form-item">'
				, '		<div class="layui-input-block">'
				, '		<fieldset class="layui-elem-field">'
				, '			<legend>选择更新资源</legend>'
				, '			<div class="layui-col-md12 layui-btn-container layui-field-box">'
				, '				<button id="btnSelDatas" class="layui-btn layui-btn-sm" data-type="tableModel">'
				, '					<i class="layui-icon">&#xe608;</i>选择表模型文件</button>'
				, '				<button id="btnSelDatas" class="layui-btn layui-btn-sm" data-type="lib">'
				, '					<i class="layui-icon">&#xe608;</i>选择jar文件</button>'
				, '				<button id="btnSelScripts" class="layui-btn layui-btn-sm" data-type="script">'
				, '					<i class="layui-icon">&#xe608;</i>选择脚本文件</button>'
				, '				<button id="btnSelStatics" class="layui-btn layui-btn-sm" data-type="file">'
				, '					<i class="layui-icon">&#xe608;</i>选择资源文件</button>'
				, '				<button id="btnSelMenu" class="layui-btn layui-btn-sm" data-type="menu">'
				, '					<i class="layui-icon">&#xe608;</i>选择菜单打包</button>'
				, '			</div>'
				, '		</fieldset>'
				, ' 	</div>'
				, ' </div>'
				, '	<div class="layui-form-item">'
				, '		<label class="layui-form-label">打包时间:</label>'
				, '		<div class="layui-input-block">'
				, '			<input type="text" name="VERP_GENGXSJ" disabled  class="layui-input">'
				, '		</div>'
				, '	</div>'
				, '	<div class="layui-form-item">'
				, '		<label class="layui-form-label">更新包路径:</label>'
				, '		<div class="layui-input-block">'
				, '				<input type="text" name="VERP_GENGXBLJ" disabled class="layui-input"> '
				, '		</div>'
				, '	</div>'
				, '	<div class="layui-form-item">'
				, '		<label class="layui-form-label">打包日志:</label>'
				, '		<div class="layui-input-block">'
				, '			<div  id="versionPackLog" required class="layui-textarea layui-div-log" disabled></div>'
				, '		</div>'
				, '	</div>'
				, '	<div class="layui-form-item' + (readonly == 'disabled' ? ' layui-hide"' : '"') + '>'
				, '		<div class="layui-input-block">'
				, '		  <button class="layui-btn' + (readonly == 'disabled' ? ' layui-btn-disabled"' : '"') + ' lay-submit lay-filter="frmGridField" ' + readonly + '>保存</button>'
				// , '		  <button type="reset" class="layui-btn layui-btn-primary ' + (type == 'edit' ? 'layui-hide"' : '"') + readonly + '>重置</button>'
				, '		</div>'
				, '	</div>'
				, '</form></div>'
			];
			layer.open({
				type: 1,
				title: readonly == 'disabled' ? '查看' : (type == 'edit' ? '编辑' : '新增'),
				id: 'coreVersionPackLayer',
				area: ['100%', '100%'],
				content: frm.join(''),
				success: function (layero, index) {
					fromlayerIndex = index;
					//重置versionPackJson
					versionPackJson.reset();
					if ('new' == type) {
						/**设置隐藏属性*/
						$('#frmGridField input[name=EDITTYPE]').val('new');
						//由于layui是主动刷新需要重新刷新才能显示出状态
						form.render();
						$('#frmGridField input[name=VER_SUOSXT]').change(function () {
							var v = $('#frmGridField input[name=VER_SUOSXT]').val();
							/**设置版本更新信息名 */
							var v1 = zlPinYin.C(v);
							$('#frmGridField input[name=VERP_BANB]').val(v1);
							form.render();
						});
					} else {
						//请求versionPackJson
						var otherParams = {
							'RWID': row['RWID'],
							'readonly': readonly
						}
						zlContext.post(layui.cache['contentPath'] + '/manager/versionpack/queryversionpackjson', otherParams, function (result) {
							if (OK == result[statusName]) {
								//编辑状态
								var retObj = result[dataName];
								var packJson = retObj["packJson"];

								zlContext.autoFill($('#frmGridField'), row);
								$('#frmGridField #versionPackLog').append(retObj['packLog']);
								$('#frmGridField input[name=EDITTYPE]').val('edit');
								$('#frmGridField select[name=VERP_CAOZXT]').val(packJson['VERP_CAOZXT']);
								$('#frmGridField select[name=VERP_DATABASE]').val(packJson['VERP_DATABASE']);
								$('#frmGridField input[name=VERP_ZUIXBB]').val(packJson['VERP_ZUIXBB']);
								$('#frmGridField input[name=VERP_YWZUIXBB]').val(packJson['VERP_YWZUIXBB']);
								for (var key in packJson) {
									versionPackJson.setTreeNodes(key, packJson[key]);
								}
								form.render();
							} else {
								layer.close(fromlayerIndex);
								zlContext.errorMsg(result[msgName]);
							}
						});
					}
					//弹出层按钮事件
					$("#frmGridField .layui-btn-container .layui-btn").on("click", function () {
						var fileType = $(this).data("type");
						//加载树形
						gridAction.treeAction.showTree(fileType, readonly);
						return false;
					})
				},
				cancel: function (index, layero) {
					if (type == 'edit' && readonly != 'disabled') {
						zlContext.isFormDataChange('frmGridField', gridAction.currentEditObj.data, gridAction, index)
						return false;
					}
				}
			});
		},
		viewRow: function (row) {
			gridAction.gridEdit(null, row, 'edit', true);
		},
		newRow: function () {
			gridAction.gridEdit(null, null, 'new', false);
		},
		editRow: function (row) {

			gridAction.gridEdit(null, row, 'edit');
		},
		deleteRows: function (rows, type) {
			if (rows.length == 0) {
				zlContext.warnMsg('请选择需要删除的升级打包信息');
				return;
			}
			zlContext.confirm('询问', '是否要删除所选的升级打包信息?', function (index) {
				// var param = { id: rows[0]['RWID'] };
				var ids = [];
				for (var i = 0; i < rows.length; i++) {
					ids.push(rows[i]['RWID'])
				}
				//提交删除
				zlContext.deletePost(layui.cache['contentPath'] + '/manager/versionpack/remove', { "ids": ids.join(",") }, function (result) {
					if (result[statusName] == OK) {
						// gridAction.currentEditObj.del();
						if (type == 'single') {
							gridAction.currentEditObj.del();
							var $pageBox = $('#tbVersionPack').siblings('div.layui-table-view').find('span.layui-laypage-count'),
								currCount = $pageBox.html().replace(/[^0-9]/ig, "");
							$pageBox.html('共 ' + --currCount + ' 条')
						} else {
							gridAction.refreshGrid('del', null);
						}
						zlContext.successMsg('删除成功');
					}
					else {
						zlContext.errorMsg(result[msgName]);
					}
				});
				layer.close(index);
			});
		},
		sumbit: function (fields) {
			var editType = $('#frmGridField input[name=EDITTYPE]').val();
			versionPackJson.VERP_CAOZXT = fields['VERP_CAOZXT'];
			delete fields['VERP_CAOZXT'];
			versionPackJson.VERP_DATABASE = fields['VERP_DATABASE'];
			delete fields['VERP_DATABASE'];
			versionPackJson.VERP_ZUIXBB = fields['VERP_ZUIXBB'];
			delete fields['VERP_ZUIXBB'];
			versionPackJson.VERP_YWZUIXBB = fields['VERP_YWZUIXBB'];
			delete fields['VERP_YWZUIXBB'];
			fields.VERP_JSON = JSON.stringify(versionPackJson);
			// var param = JSON.stringify(fields);
			if (editType == 'new') {
				zlContext.put(layui.cache['contentPath'] + '/manager/versionpack/add', fields, function (result) {
					if (result[statusName] == OK) {
						gridAction.refreshGrid(editType, result[dataName]);
						layer.close(fromlayerIndex);
						versionPackJson.reset();
						zlContext.successMsg('保存成功');
						return true;
					}
					else {
						zlContext.errorMsg(result[msgName]);
					}
				});
			} if (editType == 'edit') {
				zlContext.post(layui.cache['contentPath'] + '/manager/versionpack/modify', fields, function (result) {
					if (result[statusName] == OK) {
						if (result[dataName]) {
							fields["SYS_MODIFYTIME"] = result[dataName].SYS_MODIFYTIME
						}
						gridAction.refreshGrid(editType, fields);
						layer.close(fromlayerIndex);
						versionPackJson.reset();
						zlContext.successMsg('保存成功');
						// zlContext.successMsg(result[msgName]);
						return true;
					}
					else {
						zlContext.errorMsg(result[msgName]);
					}
				});
			}
			return false;
		},
		search: function () {
			var param = {}
			if ($('#edtSeacherValue').val().length > 0) {
				param['SEARCHVALUE'] = $('#edtSeacherValue').val();
				isloadsearch = true;
			}
			layui.event('WM_USERDEF',
				zlConfig.global.WM_USERDEF.REFRESHDATA_DATA, param);
		},
		refresh: function (node) {
			$('#edtSeacherValue').val("")
			var param = {}
			if ($('#edtSeacherValue').val().length > 0) {
				param['VERP_BANB'] = $('#edtSeacherValue').val();
			}
			layui.event('WM_USERDEF', zlConfig.global.WM_USERDEF.REFRESHDATA_DATA, param);
		},
		refreshGrid: function (type, row) {
			/**刷新行 */
			if (type == 'edit' && gridAction.currentEditObj) {
				gridAction.currentEditObj.update(row);
			}
			else {
				// table.reload('tbVersionPack');
				// gridAction.refresh()
				var addLoading = layer.load();
				versionPackTb.reload({
					where: {
						'SEARCHVALUE': ''
					},
					page: {
						curr: customCurr
					},
					done: function (res, curr, count) {
						layer.close(addLoading);
						customCurr = curr;
					}
				})
			}
		},
		startPack: function (row) {
			if (!row['VERP_JSON']) {
				zlContext.errorMsg("打包失败：未选择需要升级打包的文件");
				return;
			}
			var files = eval('(' + row['VERP_JSON'] + ')');
			var fileCount = 0;
			for (var item in files) {
				if (files[item] instanceof Array) {
					fileCount += files[item].length;
				}
			}
			if (fileCount <= 0) {
				zlContext.errorMsg("打包失败：未选择需要升级打包的文件");
				return;
			}
			var param = {},
				flag = false;
			zlContext.post(layui.cache['contentPath'] + '/manager/versionpack/pack?RWID=' + row['RWID'], param, function (result) {
				if ($('#layer_packprocesslog .dotting-container').length > 0) {
					$('#layer_packprocesslog .dotting-container').empty();
				}
				window.setTimeout(function () {
					window.clearInterval(packProcessTimer);
					$('#layer_packprocesslog').parent().find('a.layui-layer-btn0').css({
						'border-color': '#1E9FFF',
						'background-color': '#1E9FFF',
						'color': '#fff',
						'cursor': 'pointer'
					})
					flag = true
				}, 2000);
				if (result[statusName] == OK) {
					gridAction.refreshGrid('edit', result[dataName]);
					return true;
				}
				else {
					zlContext.errorMsg(result[msgName]);
				}
			}, false);
			//进度信息
			var packProcessContent = [
				'<div>'
				, '	<div class="site-text" id="packProcessLog" style="padding: 10px 10px 0 10px; line-height: 18px; font-weight: 300;">'
				, '	</div>'
				, '	<div class="site-text dotting-container" style="padding: 0 10px 10px 10px; line-height: 18px; font-weight: 300;">'
				, '		<span>处理中</span><span class="dotting"></span>'
				, '	</div>'
				, '</div>'
			];
			layer.open({
				type: 1
				, title: "打包进程" //不显示标题栏
				, closeBtn: false
				, area: ['80%', '80%']
				, id: 'layer_packprocesslog' //设定一个id，防止重复弹出
				, btn: '确认关闭'
				, moveType: 1 //拖拽模式，0或者1
				, content: packProcessContent.join('')
				, success: function (layero, index) {
					layero.find('a.layui-layer-btn0').css({
						'border-color': '#dedede',
						'background-color': '#dedede',
						'color': '#333',
						'cursor': 'not-allowed'
					})
					isPrvFinish = true;
					processLayerIndex = index;
					window.setTimeout(function () {
						packProcessTimer = window.setInterval(function () {
							if (isPrvFinish) {
								isPrvFinish = false;
								zlContext.get(layui.cache['contentPath'] + '/manager/versionpack/packprocess?t=' + Date.parse(new Date()), param, function (result) {
									var $packProcessLog = layero.find("#packProcessLog");
									if (OK == result[statusName]) {
										var msgs = result[dataName];
										for (var i = 0; i < msgs.length; i++) {
											$packProcessLog.append("<span>" + msgs[i].msg + "</span><br>");
										}
									}
									isPrvFinish = true;
								}, false);
							}
						}, 800);
					}, 200)
				},
				yes: function (index, layero) {
					if (flag) {
						layer.close(index)
					}
					gridAction.refresh(null);
					return false;
				}
			});
		},
		download: function (row) {
			loadingLayer = layer.msg('下载中，请稍候...', { icon: 16, time: false, shade: 0.1 });
			var _downloadid = new Date().getTime();
			var url = layui.cache['contentPath'] + '/manager/versionpack/download?id=' + row['RWID'] + '&_downloadid=' + _downloadid;
			if ($("#ifdownload").length == 0) {
				$("body").append('<iframe id=ifdownload style="display:none"></iframe>');
			}
			$("#ifdownload").attr("src", url);
			var iframe = document.getElementById('ifdownload');
			iframe.onload = iframe.onreadystatechange = function iframeload() {
				if (intervalId) {
					clearInterval(intervalId);
				}
				layer.close(loadingLayer);
				if (!iframe.readyState || iframe.readyState == "complete") {
					var iframeText = document.getElementById('ifdownload').contentWindow.document;
					iframeText = $(iframeText).text();
					if (iframeText) {
						var obj = JSON.parse(iframeText);
						zlContext.errorMsg(obj.msg);
					}

				}
			};
			intervalId = setInterval(function () {
				var cookieName = '_downloadid' + _downloadid;
				var cookieValue = zlContext.getCookieValue(cookieName);
				if (cookieValue && cookieValue == _downloadid) {
					layer.close(loadingLayer);
					if (intervalId) {
						clearInterval(intervalId);
						intervalId = undefined;
					}
				}
			}, 500);
		},
		treeAction: {
			treeObj: undefined,
			loadingLayerIndex: undefined,
			showTree: function (fileType, readonly) {
				var treeContent = [
					'<div class="layui-card-body zltree-body">'
					, '	<div class="ztree-wrap">'
					, '		<ul id="dirTreeId" class="ztree" style="overflow-x:hidden;" url="${request.contextPath}/manager/versionpack/shownode"></ul>'
					, '	</div>'
					, '</div>'
				];

				layer.open({
					type: 1,
					title: readonly == 'disabled' ? '查看' : "选择",
					btn: readonly == 'disabled' ? ['返回'] : ['确定', '重置'],
					// btnAlign:'l',
					id: 'checkChooseLayer',
					area: ['500px', '500px'],
					content: treeContent.join(''),
					success: function (layero, index) {
						treeLayerIndex = index;
						//创建zTree组件
						var setting = {
							view: {
								showLine: true
							},
							check: {
								autoCheckTrigger: true,
								chkboxType: { "Y": "ps", "N": "ps" },
								chkStyle: "checkbox",
								enable: readonly == 'disabled' ? false : true,
								chkDisabledInherit: true
							},
							data: {
								key: {
									name: 'name'
								}
								, simpleData: {
									enable: true
									, idKey: 'id'
									, pIdKey: 'parentId'
									, rootPid: null
								}
							},
							callback: {
								onClick: function (event, treeId, treeNode) {
									//触发刷新的事件
									//	treeAction.raiseResDataEvent(treeNode);
								},
							}
						};
						if (readonly == 'disabled') {
							//查看状态
							//初始化树结构
							$.fn.zTree.init($('#dirTreeId'), setting, versionPackJson.getTreeNodes(fileType));
							treeObj = $.fn.zTree.getZTreeObj('dirTreeId');
						} else {
							//编辑状态
							gridAction.treeAction.requestTreeNodes(setting, fileType);
						}
					},
					yes: function (index, layero) {
						if (readonly == 'disabled') {
							layer.close(index);
							return;
						}
						var nodes = [];
						var chkNodes = treeObj.getCheckedNodes(true);
						for (var i = 0; i < chkNodes.length; i++) {
							var item = chkNodes[i];
							var halfCheck = item.getCheckStatus();
							if (fileType == 'menu') {
								nodes.push(item.id);
							} else {
								if (!halfCheck.half) {
									if (!item.isParent) {
										nodes.push(item.id);
									} else {
										//空文件夹
										var children = item.children;
										if (!children) {
											nodes.push(item.id);
										}
									}
								}
							}
						}
						versionPackJson.setTreeNodes(fileType, nodes);
						layer.close(index);
					},
					btn2: function (index, layero) {
						//重置
						treeObj.checkAllNodes(false);
						return false;
					}
				});
			},
			requestTreeNodes: function (setting, fileType) {
				//请求参数
				var otherParams = {
					"type": fileType
				}
				zlContext.post(layui.cache['contentPath'] + '/manager/versionpack/shownode', otherParams, function (result) {
					if (OK == result[statusName]) {
						//初始化树结构
						$.fn.zTree.init($('#dirTreeId'), setting, result[dataName]);
						treeObj = $.fn.zTree.getZTreeObj('dirTreeId');
						if (result[dataName] && result[dataName].length == 1 && fileType != 'menu') {
							var node = treeObj.getNodeByParam('id', result[dataName][0].id, null);
							treeObj.setChkDisabled(node, true);
						}
						var selNodes = versionPackJson.getTreeNodes(fileType);
						var len = selNodes.length;
						for (var i = 0; i < len; i++) {
							var node = treeObj.getNodeByParam('id', selNodes[i], null);
							if (node) {
								if (fileType == 'menu') {
									treeObj.checkNode(node, true, false);
								} else {
									treeObj.checkNode(node, true, true);
								}

							}
						}
					}
					else {
						zlContext.errorMsg(result[msgName]);
						layer.close(treeLayerIndex);
					}
				});
			}
		}
	}

	// $('#btnSeacher').on('click', function () {
	// 	customCurr = 1;
	// 	gridAction.search();
	// });
	$('.zl-container').on('keyup', '#edtSeacherValue', function (event) {
		var keyCode = event.keyCode;
		customCurr = 1;
		$('.zl-container').attr('data-search', $(this).val())
		if (keyCode == 13) {
			gridAction.search();
		}
		if ((keyCode == '46' || keyCode == '8' || (event.ctrlKey && keyCode == '86')) && $(this).val() == '' && isloadsearch) {
			$('#btnSeacher').trigger('click');
			isloadsearch = false;
		}
	});
	//头工具栏事件
	table.on('toolbar(tbVersionPack)', function (obj) {
		var checkStatus = table.checkStatus(obj.config.id);
		switch (obj.event) {
			case 'btnSeacher':
				customCurr = 1;
				gridAction.search();
				break;
			case 'addVersionPack':
				gridAction.newRow();
				break;
			case 'deleteVersionPack':
				var rows = checkStatus.data;
				gridAction.deleteRows(rows, 'multi');
				break;
			case 'refreshVersionPack':
				gridAction.refresh(null);
				break;
		};
	});
	//监听行工具事件
	table.on('tool(tbVersionPack)', function (obj) {
		var row = obj.data; //获得当前行数据
		var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
		var tr = obj.tr; //获得当前行 tr 的DOM对象
		if (layEvent === 'detail') { //查看
			gridAction.viewRow(row)
		} else if (layEvent === 'del') { //删除
			gridAction.currentEditObj = obj;
			gridAction.deleteRows([row], 'single');
		} else if (layEvent === 'edit') { //编辑
			gridAction.currentEditObj = obj;
			gridAction.editRow(row);
		} else if (layEvent === 'execute') { //打包
			gridAction.currentEditObj = obj;
			gridAction.startPack(row);
		} else if (layEvent === 'download') { //下载
			gridAction.currentEditObj = obj;
			gridAction.download(row);
		}

	});

	//	//排序事件
	//	table.on('sort(tbVersionPack)', function(obj){
	//		versionPackTb.reload({
	//			url: layui.cache['contentPath'] + '/manager/versionpack/query',
	//			initSort: obj //记录初始排序，如果不设的话，将无法标记表头的排序状态。 layui 2.1.1 新增参数
	//		    ,where: { //请求参数（注意：这里面的参数可任意定义，并非下面固定的格式）
	//		      field: obj.field //排序字段   在接口作为参数字段  field order
	//		      ,order: obj.type //排序方式   在接口作为参数字段  field order
	//		    }
	//		});
	//	});

	//提交
	form.on('submit(frmGridField)', function (frm) {
		if ($(frm.elem).hasClass('getField')) {
			gridAction.newFields = frm.field
			return false;
		}
		return gridAction.sumbit(frm.field);
	});

	//版本校验
	form.verify({
		verifyBackspace: function (value, item) {
			if (value) {
				if (/^\s+|\s+|\s+$/g.test(value)) {
					$(item).focus();
					return '输入值中不能包含空格';
				}
			}
		}
	});

	//监听刷新的事件
	layui.event('WM_USERDEF', zlConfig.global.WM_USERDEF.REFRESHDATA_DATA, null, function (param) {
		var index = layer.msg('数据查询中，请稍候...', { icon: 16, time: false, shade: 0.1 });
		var loadGridData = function (tableId, url, param) {
			//  当param为空时，会将上次的缓存参数再次传入后台 需使用方法级渲染
			versionPackTb.reload({
				url: url
				, height: fullheight
				, method: 'post'
				, page: {
					curr: customCurr
				}
				, where: param
				, page: {
					curr: 1 //重新从第 1 页开始
				}
				, done: function (res, curr, count) {
					$('#edtSeacherValue').val($('.zl-container').attr('data-search'))
					layer.close(index);
					customCurr = curr;
				}
			});
		}
		//刷新
		loadGridData('tbVersionPack', layui.cache['contentPath'] + '/manager/versionpack/query', param);
	});
	gridAction.refresh(null);
	//控制高度的设置
	function setMaxHeihgt(deff, deff1) {
		$('.docking-left').height($(window).height() - deff);
		$('.docking-fill').height($(window).height() - deff);
		var treeHeaderH = $('.zltree-header').height();
		$('.layui-card-body').height($(window).height() - deff1);
		$('.zltree-body').height($('.layui-card-body').height() - treeHeaderH - 20);
	}
	$(window).on('resize', function () {
		//控制高度的设置
		setMaxHeihgt(16, 32);
	}).resize();
});